#include <cppunit/config/SourcePrefix.h>
#include "TestVarTableEntry.h"
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

void TestVarTableEntry::setUp() {}

void TestVarTableEntry::tearDown() {
}

CPPUNIT_TEST_SUITE_REGISTRATION( TestVarTableEntry );

void TestVarTableEntry::testVarTableEntry(){
	VarTableEntry entry("x",0);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("entry 0 created", 0, entry.getEntryNo());
	CPPUNIT_ASSERT_EQUAL_MESSAGE("name of entry is \"x\"", string("x"), entry.getName());
	CPPUNIT_ASSERT_MESSAGE("initial stmtNumbers is not null and empty", entry.getStmtNumbers().empty());
	CPPUNIT_ASSERT_MESSAGE("initial NodeIDs is not null and empty", entry.getNodeIDs().empty());
}

void TestVarTableEntry::testAddStmtNumber(){
	VarTableEntry entry("x",0);
	entry.addStmtNumber(0);
	CPPUNIT_ASSERT_MESSAGE("entry stmtNumbers contain 0", 
							find(entry.getStmtNumbers().begin(),entry.getStmtNumbers().end(),0) != entry.getStmtNumbers().end());
	entry.addStmtNumber(1);
	CPPUNIT_ASSERT_MESSAGE("entry stmtNumbers contain 0 and 1",
							entry.getStmtNumbers().size() == 2
							&& find(entry.getStmtNumbers().begin(),entry.getStmtNumbers().end(),0) != entry.getStmtNumbers().end()
							&& find(entry.getStmtNumbers().begin(),entry.getStmtNumbers().end(),1) != entry.getStmtNumbers().end());
	entry.addStmtNumber(1);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("entry stmtNumbers still contains only 2 entries", 
								2, (int) entry.getStmtNumbers().size());	
}

void TestVarTableEntry::testAddNodeID(){
	VarTableEntry entry("x",0);
	entry.addNodeID(0);
	CPPUNIT_ASSERT_MESSAGE("entry NodeIDs contain 0", 
		find(entry.getNodeIDs().begin(),entry.getNodeIDs().end(),0) != entry.getNodeIDs().end());
	entry.addNodeID(1);
	CPPUNIT_ASSERT_MESSAGE("entry NodeIDs contain 0 and 1", 
							find(entry.getNodeIDs().begin(),entry.getNodeIDs().end(),0) != entry.getNodeIDs().end()
							&& find(entry.getNodeIDs().begin(),entry.getNodeIDs().end(),1) != entry.getNodeIDs().end());
	entry.addNodeID(1);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("entry NodeIDs contain only 2 entries", 2, (int) entry.getNodeIDs().size());	
}